package sunwin.yoms.service.person;

import org.springframework.stereotype.Service;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.dao.UserRoleDao;
import sunwin.yoms.domain.person.UserRoleDomain;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by watson on 2015/7/30.
 */
@Service
public class UserRoleService {
    private UserRoleDao userRoleDao;

    //查询
    public List<UserRoleDomain> getUserRole(UserRoleDomain userRoleDomain) {
        List<UserRoleDomain> userRoleDomains = new ArrayList<UserRoleDomain>();
        userRoleDomains = userRoleDao.getDomainCollection(userRoleDomain);
        return userRoleDomains;
    }

    //id查询
    public UserRoleDomain getUserRoleById(int userRoleId) {
        return userRoleDao.getDomainById(userRoleId);
    }

    //总数
    public int getUserRoleCount() {
        return userRoleDao.getDomainCount();
    }

    //增加
    public void addUserRole(UserRoleDomain userRoleDomain) throws YomsException {
        if (userRoleDao.addDomain(userRoleDomain) != 1) {
            throw new YomsException("增加用户角色失败");
        }
    }

    //更新
    public void upUserRole(UserRoleDomain userRoleDomain) throws YomsException {
        if (userRoleDao.updateDomain(userRoleDomain) != 1) {
            throw new YomsException("更新用户角色失败");
        }
    }

    //删除
    public void deleteUserRole(UserRoleDomain userRoleDomain) throws YomsException {
        if (userRoleDao.deleteDomain(userRoleDomain) != 1) {
            throw new YomsException("删除用户角色失败");
        }
    }
}
